﻿using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using Zoxel.Voxels;

namespace Zoxel
{
    [CreateAssetMenu(fileName = "Character", menuName = "Zoxel/Character")]
    public class CharacterDatam : ScriptableObject, ISerializationCallbackReceiver
    {
        public MonsterData Value;
        public float movementSpeed = 2;
        public float turnSpeed = 2;
        public float maxVelocity = 6;

        public BehaviourDatam behaviour;
        public ClassDatam defaultClass;
        public List<SkillDatam> skills;
        public List<QuestDatam> quests;
        public List<QuestDatam> questsToGive;   // do i need this

        [Header("Items")]
        public List<ItemDatam> items;
        public float itemPickupRadius;  // keep 0 if has no pickup component
        // scripted item drops
        public List<ItemDrop> dropItems;

        [Header("Art")]
        public VoxDatam vox;
        public List<ItemDatam> body;
        public List<ItemDatam> gear;
        //public AnimatorDatam animator;
        // this can be generated by body parts?
        //public SkeletonDatam skeleton;      // spawn this if has it

        [Header("Audio")]
        public SoundDatam spawnSound;
        public SoundDatam deathSound;

        [Header("Stats")]
        public Stats stats;

        [ContextMenu("Generate ID")]
        public void GenerateID()
        {
            Value.GenerateID();
        }
        [ContextMenu("Print Size")]
        public void PrintSize()
        {
            Debug.Log(vox.data.GetSize().ToString());
            Debug.Log("Floored Y: " + math.floor(vox.data.GetSize().y));
        }

        #region SerializeableComponents
        // [HideInInspector]
        public Stats.SerializeableStats statsClone;

        public void OnBeforeSerialize()
        {
            statsClone = stats.GetSerializeableClone();
        }

        public void OnAfterDeserialize()
        {
            if (statsClone.stats != null)
            {
                stats.FromClone(statsClone);
            }
        }

        [ContextMenu("RemoveBaseStats")]
        public void RemoveBaseStats()
        {
            stats.stats = new BlitableArray<Staz>(0, Unity.Collections.Allocator.Persistent);
            statsClone.stats = new Staz[0];
        }
        #endregion
    }
}